//
//  SceneryDetailCell.m
//  lv678
//
//  Created by apple on 15/9/9.
//  Copyright (c) 2015年 lampshade. All rights reserved.
//  自定义景点详情单元格

#define viewW  self.superview.frame.size.width
#define viewH  self.superview.frame.size.height

#import "SceneryDetailCell.h"
#import "SceneryDetailModel.h"
#import "SceneryOrderController.h"
#import "SceneryDetailController.h"
#import "AppDelegate.h"
#import "loginController.h"
@interface SceneryDetailCell()
@property (nonatomic, assign) int ProductID;
@property (nonatomic, copy) NSString *PassportType;
@end
@implementation SceneryDetailCell

- (void)awakeFromNib {

    self.sceneryDetailName.lineBreakMode = NSLineBreakByWordWrapping;
    self.sceneryDetailName.numberOfLines = 0;
    
    self.sceneryOrder.layer.cornerRadius = 6;
    [self.sceneryOrder addTarget:self action:@selector(pushView) forControlEvents:UIControlEventTouchUpInside];
    
//    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewDetail)];
//    recognizer.numberOfTapsRequired = 1;
//    [self.lblDetail addGestureRecognizer:recognizer];
}

//- (void)viewDetail{
//    UIView *detailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, viewW,viewH)];
//    detailView.backgroundColor = [UIColor blackColor];
//    detailView.alpha = 1;
//    [self.superview addSubview:detailView];
//}
#pragma mark - 设置自定义cell数据
-(void)setData:(SceneryDetailModel *)model{
    self.model = model;
    self.PassportType = self.model.PayMode;
    NSString *time = [self.model.CanBookingLimitTime substringFromIndex:11];
    time = [[time substringToIndex:5] stringByAppendingString:@"前接受预定"];
    NSString *date = @"(需提前";
    date = [[date stringByAppendingString:self.model.AdvanceBookingDays]stringByAppendingString:@"天)"];
    NSString *markPrice = @"市场价￥";
    markPrice = [markPrice stringByAppendingString:[NSString stringWithFormat:@"%d",self.model.MarketPrice]];
    NSString *price = @"￥";
    price = [price stringByAppendingString:[NSString stringWithFormat:@"%d",self.model.Price]];
    
    self.sceneryDetailName.text = self.model.Name;
    self.CanBookingLimitTime.text = time;
    self.AdvanceBookingDays.text = date;
    self.resourceID.text = [NSString stringWithFormat:@"%d",_model.ID];
    self.MarketPrice.text = markPrice;
    self.Price.text = price;
    if ([self.model.PayMode isEqualToString:@"P"]) {
        self.PayMode.text = @"在线支付";
    }else{
        self.PayMode.text = @"到付";
    }
}

#pragma mark - 预定使用代理进行页面跳转
- (void)pushView{
//    AppDelegate *app = [[AppDelegate alloc]init];
    int ID = [self.resourceID.text intValue];
    NSString *sceneryName = self.sceneryDetailName.text;
    NSDictionary *dict = @{@"ResourceID":[NSString stringWithFormat:@"%d",ID],@"sceneryName":sceneryName,@"PassportType":self.PassportType};

    //获取storyboard中的景点订单视图
    SceneryOrderController *detailController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"sceneryOrder"];
//    loginController *login = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"login"];

    //判断是否实现代理，如果实现，利用代理将参数传到代理类中
    if ([self.delegate respondsToSelector:@selector(pushViewController:sendValue:)]) {
//        if ([app.loginInfo objectForKey:@"userName"] != nil ) {
            [self.delegate pushViewController:detailController sendValue:dict];
//        }else{
//            [self.delegate pushViewController:login sendValue:nil];
//        }
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
